package public

import (
	"go.uber.org/zap"
	"log"
	"sync"
)

type Service struct {
	Logger *zap.Logger
}

var service *Service
var once sync.Once
var logger *zap.Logger

func init() {
	once.Do(func() {
		service = createService()
		logger = createLogger()
	})
}

func GetBaseService() *Service {
	if service == nil {
		log.Fatal("cannot create service")
	}
	return service
}

func createService() *Service {
	Logger, err := zap.NewDevelopment()
	if err != nil {
		log.Fatalf("cannot create logger: %v", err)
	}
	return &Service{Logger: Logger}
}

func GetLogger() *zap.Logger {
	if logger == nil {
		log.Fatal("cannot create logger")
	}
	return logger
}

func createLogger() *zap.Logger {
	l, err := zap.NewDevelopment()
	if err != nil {
		log.Fatalf("cannot create logger: %v", err)
	}
	return l
}
